#CC = g++ -O3
#CC = gcc
CC = g++ -O3
#CC = gcc -g

INCLUDES = stream sort app 

CFLAGS = $(INCLUDES:%=-I%)

LIBDIRS = #/usr/X11R6/lib/

#FRAMEWORKS = Foundation #OpenGL GLUT
LIBS = m #lapack blas g2c glut GLU GL Xi Xmu
LFLAGS = $(LIBDIRS:%=-L%) $(LIBS:%=-l%) #$(FRAMEWORKS:%=-framework %) 

CSOURCES = \
	stream/inputbufferstream\
	stream/outputbufferstream\
	stream/inputelementstream\
	stream/outputelementstream\
	stream/outputfilestream\
	stream/inputfilestream\
	stream/inputmemorystream\
	stream/outputmemorystream\
	sort/dWayMerge_class\
	sort/quicksort\
	sort/random
#app/testBufferStream\
#	app/testElementStream\
#	app/testFileStream\
#	app/testMemoryStream

CTESTS = 

SOURCES =  $(CSOURCES)
OBJS = $(SOURCES:%=%.o)
HDRS = $(SOURCES:%=%.h) 

TEST_SOURCES = $(CTESTS) 
TEST_OBJS = $(TEST_SOURCES:%=%.o)

EXECS = ExtMSortMemoryStream\
	ExtMSortFileStream\
	ExtMSortBufferStream\
	ExtMSortElementStream 

all: $(EXECS)

clean:
	\rm -f $(OBJS) $(CAPPS:%=%.o) *~ $(EXECS) $(EXECS:%=%.o) $(TESTS:%=%.o) $(INCLUDES:%=%/*~) 

streams/%.o: streams/%.c Makefile $(SOURCES:%=%.h)
	$(CC) -c $(CFLAGS) $< -o $@

sort/%.o: sort/%.c Makefile $(SOURCES:%=%.h)
	$(CC) -c $(CFLAGS) $< -o $@

#testFileStream: app/testFileStream.o app/testFileStream.cpp
#	$(CC) app/testFileStream.cpp stream/inputfilestream.o  stream/outputfilestream.o -o $@

#testElementStream:  app/testElementStream.o app/testElementStream.cpp
#	$(CC) app/testElementStream.cpp stream/inputelementstream.o stream/outputelementstream.o -o $@

#testBufferStream:  app/testBufferStream.o app/testBufferStream.cpp
#	$(CC) app/testBufferStream.cpp stream/inputbufferstream.o stream/outputbufferstream.o -o $@

#testMemoryStream: app/testMemoryStream.o app/testMemoryStream.cpp
#	$(CC) app/testMemoryStream.cpp stream/inputmemorystream.o stream/outputmemorystream.o  -o $@
 

ExtMSortMemoryStream: $(OBJS)  app/ExtMSortMemoryStream.cpp
	$(CC) app/ExtMSortMemoryStream.cpp -Xlinker $(OBJS)  $(LFLAGS) -o $@  

ExtMSortFileStream: $(OBJS)  app/ExtMSortFileStream.cpp
	$(CC) app/ExtMSortFileStream.cpp -Xlinker $(OBJS)  $(LFLAGS) -o $@  

ExtMSortBufferStream: $(OBJS)  app/ExtMSortBufferStream.cpp
	$(CC) app/ExtMSortBufferStream.cpp -Xlinker $(OBJS)  $(LFLAGS) -o $@  

ExtMSortElementStream: $(OBJS)  app/ExtMSortFileStream.cpp
	$(CC) app/ExtMSortElementStream.cpp -Xlinker $(OBJS)  $(LFLAGS) -o $@  
